﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input.Touch;
using Imaginecup.util.input;

namespace Imaginecup.util.touchMan
{
    public class TouchUtil
    {
        public static void Update( TouchCollection touchCollection , TouchMan touchMan ,
            ITouchProcessRegister touchRegister )
        {
            foreach (TouchLocation touch in touchCollection)
            {

                if (touchMan.IsContainTouch(touch.Id) == false)
                {
                    touchRegister.RegisterTouch(touch);
                }
                
                if( touchMan.IsContainTouch(touch.Id) )
                {
                    Update(touch, touchMan.GetTouchProcess(touch.Id));
                }
            }
        }

        private static void Update( TouchLocation touch , ITouchProcess touchProcess )
        {
            if( touch.State == TouchLocationState.Pressed )
            {
                touchProcess.TouchBegan(touch);
            }
            else if( touch.State == TouchLocationState.Moved )
            {
                touchProcess.TouchMove(touch);
            }
            else if( touch.State == TouchLocationState.Released )
            {
                touchProcess.TouchEnd(touch);
            }
        }
    }
}
